package com.ymatou.iapi.productsnapshot.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.AddSellerProductCall;
import com.ymatou.iapi.productsnapshot.parameter.AddProductSnapshotBean;
import com.ymatou.iapi.productsnapshot.parameter.Props;
import com.ymatou.iapi.productsnapshot.parameter.Templates;
import com.ymatou.iapi.productsnapshot.service.AddProductSnapshotCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.business.service.ProductPriceCallService;
import com.ymttest.database.mongo.ProductsWapper;
import com.ymttest.database.mongo.SnapShotWapper;
import com.ymttest.utils.TestDataManager;

/**
 * 创建快照 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_AddProductSnapshot {
	private static AddProductSnapshotBean addproductsnapshotBean;
	private static AddProductSnapshotCall addproductsnapshotCall;
	SnapShotWapper ssw;
	ProductsWapper ps;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建快照");
	}

	@Before
	public void caseUp() throws Exception {
		addproductsnapshotBean = new AddProductSnapshotBean();
		addproductsnapshotCall = new AddProductSnapshotCall();
		ssw = new SnapShotWapper();
		ps = new ProductsWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addproductsnapshotCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 更新信息
	 * 
	 * @param pid
	 *            商品pid
	 * @param i
	 *            1为更新pkey 2为更新ckey 3为更新pickey
	 * @return 返回对应更新的字段 <br>
	 *         1 {scatid=2002, tcatname=三级分类名, scatname=二级分类名, mcatid=2001,
	 *         pcode=商品备案号, tariffy=4, deliv=2, title=自动化测试title1504172104273,
	 *         mcatname=一级分类名, shipping=false, intro=简介1504172104342, action=6,
	 *         mdeliv=7, brand=自动化测试brand, ispsp=true, noreason=false,
	 *         mflight=8,
	 *         templates=[com.ymatou.iapi.productsnapshot.parameter.Templates@173b51b],
	 *         bonded=3, tcatid=2003, ebrand=auto test ebrand, localr=5,
	 *         ctype=1, wtu=9, bid=1002, desc=文字描述} <br>
	 *         2 {newp=3, price=10, isexd=false, vip=2, presale=true, wt=4,
	 *         pkg=true, cid=022cb6a4-7098-4753-baab-0bda3c6ef7ae,
	 *         attrs=[com.ymatou.iapi.productsnapshot.parameter.Props@ef3420]}
	 *         <br>
	 *         3
	 * @throws Exception
	 * @throws NumberFormatException
	 */
	private Map<String, Object> UpdateInfo(String spid, int i) throws NumberFormatException, Exception {
		Map<String, Object> m = new HashMap<String, Object>();
		if (i == 1) {
			String title = "自动化测试title" + new Date().getTime();
			ps.updateProductsBySpid(spid, "title", title);
			m.put("title", title);

			String intro = "简介" + new Date().getTime();
			ps.updateProductsBySpid(spid, "intro", intro);
			m.put("intro", intro);

			int bid = 1002;
			ps.updateProductsBySpid(spid, "bid", bid);
			m.put("bid", bid);

			String brand = "自动化测试brand";
			ps.updateProductsBySpid(spid, "brand", brand);
			m.put("brand", brand);

			String ebrand = "auto test ebrand";
			ps.updateProductsBySpid(spid, "ebrand", ebrand);
			m.put("ebrand", ebrand);

			int mcatid = 2001;
			ps.updateProductsBySpid(spid, "mcatid", mcatid);
			m.put("mcatid", mcatid);

			String mcatname = "一级分类名";
			ps.updateProductsBySpid(spid, "mcatname", mcatname);
			m.put("mcatname", mcatname);

			int scatid = 2002;
			ps.updateProductsBySpid(spid, "scatid", scatid);
			m.put("scatid", scatid);

			String scatname = "二级分类名";
			ps.updateProductsBySpid(spid, "scatname", scatname);
			m.put("scatname", scatname);

			int tcatid = 2003;
			ps.updateProductsBySpid(spid, "tcatid", tcatid);
			m.put("tcatid", tcatid);

			String tcatname = "三级分类名";
			ps.updateProductsBySpid(spid, "tcatname", tcatname);
			m.put("tcatname", tcatname);

			int ctype = 1;
			ps.updateProductsBySpid(spid, "ctype", ctype);
			m.put("ctype", ctype);

			int deliv = 2;
			ps.updateProductsBySpid(spid, "deliv", deliv);
			m.put("deliv", deliv);

			int bonded = 3;
			ps.updateProductsBySpid(spid, "bonded", bonded);
			m.put("bonded", bonded);

			String pcode = "商品备案号";
			ps.updateProductsBySpid(spid, "pcode", pcode);
			m.put("pcode", pcode);

			int tariffy = 4;
			ps.updateProductsBySpid(spid, "tariffy", tariffy);
			m.put("tariffy", tariffy);

			int localr = 5;
			ps.updateProductsBySpid(spid, "localr", localr);
			m.put("localr", localr);

			boolean noreason = false;
			ps.updateProductsBySpid(spid, "noreason", noreason);
			m.put("noreason", noreason);

			int action = 6;
			ps.updateProductsBySpid(spid, "action", action);
			m.put("action", action);

			String desc = "文字描述";
			ps.updateProductDescExtraBySpid(spid, "desc", desc);
			m.put("desc", desc);

			boolean ispsp = true;
			ps.updateProductsBySpid(spid, "ispsp", ispsp);
			m.put("ispsp", ispsp);

			int mdeliv = 7;
			ps.updateProductsBySpid(spid, "mdeliv", mdeliv);
			m.put("mdeliv", mdeliv);

			int mflight = 8;
			ps.updateProductsBySpid(spid, "mflight", mflight);
			m.put("mflight", mflight);

			int wtu = 9;
			ps.updateProductsBySpid(spid, "wtu", wtu);
			m.put("wtu", wtu);

			List<Templates> templates = new ArrayList<>();
			if (new Random().nextBoolean()) {
				Templates e = new Templates();
				e.setCls(10);
				e.setTlid(11);
				templates.add(e);
				ps.updateProductsBySpid(spid, "templates", templates);
				m.put("templates", templates);
			} else {
				Templates e = new Templates();
				ps.updateProductsBySpid(spid, "templates", templates);
				m.put("templates", templates);
			}

			// templates 在表中为空是true 其他情况是false
			if (templates.isEmpty()) {
				m.put("shipping", true);
			} else {
				m.put("shipping", false);
			}
		} else if (i == 2) {
			Map<String, Object> m2 = ps.getCatalogsBySpid(spid).get(0);
			m.put("cid", m2.get("cid").toString());
			int mde = new Random().nextInt(2);
			ps.updateCatalogsByCid(m2.get("cid").toString(), "mdeliv", mde);
			if (mde == 0) {
				m.put("isexd", false);
			} else {
				m.put("isexd", true);
			}
			ps.updateCatalogsByCid(m2.get("cid").toString(), "presale", true);
			m.put("presale", true);

			ps.updateCatalogsByCid(m2.get("cid").toString(), "price", 10);
			m.put("price", 10);

			ps.updateCatalogsByCid(m2.get("cid").toString(), "vip", 2);
			m.put("vip", 2);

			ps.updateCatalogsByCid(m2.get("cid").toString(), "newp", 3);
			m.put("new", 3);

			ps.updateCatalogsByCid(m2.get("cid").toString(), "wt", 4);
			m.put("weight", 4);

			List<Props> props = new ArrayList<>();
			Props e = new Props();
			e.setName("name");
			e.setValue("value");
			e.setPic("pic");
			props.add(e);
			ps.updateCatalogsByCid(m2.get("cid").toString(), "props", (props));
			m.put("props", props);

			ps.updateCatalogsByCid(m2.get("cid").toString(), "package", true);
			m.put("pkg", true);
		} else if (i == 3) {
			ps.updateProductsBySpid(spid, "pics", Arrays.asList("mainpics1", "mainpics2"));
			m.put("mainpics", Arrays.asList("mainpics1", "mainpics2"));
			ps.updateProductDescExtraBySpid(spid, "descpics", Arrays.asList("descpics"));
			m.put("descpics", Arrays.asList("descpics"));
			ps.updateProductDescExtraBySpid(spid, "sizepics", Arrays.asList("sizepics"));
			m.put("sizepics", Arrays.asList("sizepics"));
			ps.updateProductDescExtraBySpid(spid, "notice", "notice");
			m.put("notice", "notice");
			ps.updateProductDescExtraBySpid(spid, "notipics", Arrays.asList("notipics"));
			m.put("notipics", Arrays.asList("notipics"));
			ps.updateProductDescExtraBySpid(spid, "intro", "intro");
			m.put("intro", "intro");
			ps.updateProductDescExtraBySpid(spid, "intropics", Arrays.asList("intropics"));
			m.put("intropics", Arrays.asList("intropics"));
			ps.updateProductDescExtraBySpid(spid, "cdpics", Arrays.asList("cdpics"));
			m.put("cdpics", Arrays.asList("cdpics"));

			List<Props> props = new ArrayList<>();
			Props e = new Props();
			e.setKey("key1");
			e.setValue("value1");
			props.add(e);

			ps.updateProductDescExtraBySpid(spid, "props", props);
			m.put("props", props);
			
			Map v=new HashMap();
			ps.updateProductsBySpid(spid, "v",new HashMap());
			ps.updateProductsBySpid(spid, "v.u","http://www.ymatou.com");
			v.put("u", "http://www.ymatou.com");
			ps.updateProductsBySpid(spid, "v.l",100);
			v.put("l", 100);
			ps.updateProductsBySpid(spid, "v.w",50);
			v.put("w", 50);
			ps.updateProductsBySpid(spid, "v.h",30);
			v.put("h", 30);
			ps.updateProductsBySpid(spid, "v.s",90);
			v.put("s", 90);
			m.put("v", v);
		}
		return m;
	}

	private void verifyDB(Map productsmapdate, String pid, int i) throws Exception {
		List<String> keys = new ArrayList<>();
		keys.add("pid");
		keys.add("ver");
		keys.add("ckey");
		keys.add("pkey");
		keys.add("pickey");
		ArrayList<Map> list = ssw.getProductVersionInfoLens(pid, 1, keys);
		String pkey = list.get(0).get("pkey").toString();
		String ckey = list.get(0).get("ckey").toString();
		String pickey = list.get(0).get("pickey").toString();
		if (i == 1) {
			Map m1 = ssw.getProductCoreInfo(pid, pkey).get(0);
			Logger.comment("验证ProductCoreInfo");
			Logger.verifyEquals(productsmapdate.get("title"), m1.get("title"), "验证title");
			Logger.verifyEquals(productsmapdate.get("intro"), m1.get("intro"), "验证intro");
			Logger.verifyEquals(productsmapdate.get("bid"), m1.get("bid"), "验证bid");
			Logger.verifyEquals(productsmapdate.get("brand"), m1.get("brand"), "验证brand");
			Logger.verifyEquals(productsmapdate.get("ebrand"), m1.get("ebrand"), "验证ebrand");
			Logger.verifyEquals(productsmapdate.get("mcatid"), m1.get("masterid"), "验证masterid");
			Logger.verifyEquals(productsmapdate.get("mcatname"), m1.get("mastername"), "验证mastername");
			Logger.verifyEquals(productsmapdate.get("scatid"), m1.get("cateid"), "验证cateid");
			Logger.verifyEquals(productsmapdate.get("scatname"), m1.get("catename"), "验证catename");
			Logger.verifyEquals(productsmapdate.get("tcatid"), m1.get("thirdid"), "验证thirdid");
			Logger.verifyEquals(productsmapdate.get("tcatname"), m1.get("thirdname"), "验证thirdname");
			Logger.verifyEquals(productsmapdate.get("ctype"), m1.get("ctype"), "验证ctype");
			Logger.verifyEquals(productsmapdate.get("deliv"), m1.get("delivery"), "验证delivery");
			Logger.verifyEquals(productsmapdate.get("bonded"), m1.get("bonded"), "验证bonded");
			Logger.verifyEquals(productsmapdate.get("pcode"), m1.get("pcode"), "验证pcode");
			Logger.verifyEquals(productsmapdate.get("shipping"), m1.get("shipping"), "验证shipping");
			Logger.verifyEquals(productsmapdate.get("tariffy"), m1.get("tariffy"), "验证tariffy");
			Logger.verifyEquals(productsmapdate.get("localr"), m1.get("local"), "验证local");
			Logger.verifyEquals(productsmapdate.get("noreason"), m1.get("noreason"), "验证noreason");
			Logger.verifyEquals(productsmapdate.get("action"), m1.get("action"), "验证action");
			Logger.verifyEquals(productsmapdate.get("desc"), m1.get("desc"), "验证desc");
			Logger.verifyEquals(productsmapdate.get("ispsp"), m1.get("psp"), "验证psp");
			// ?
			// Logger.verifyEquals(m.get("grade"), m1.get("grade"),"验证grade");
			// Logger.verifyEquals(m.get("own"), m1.get("own"),"验证own");
			Logger.verifyEquals(productsmapdate.get("mdeliv"), m1.get("exdtype"), "验证exdtype");
			Logger.verifyEquals(Double.valueOf(productsmapdate.get("mflight").toString()), Double.valueOf(m1.get("exdfee").toString()), "验证exdfee");
			List<Templates> ts = (List<Templates>) productsmapdate.get("templates");
			if (ts != null && !ts.isEmpty()) {
				Map mtmp = (Map) ((List) m1.get("temps")).get(0);
				Logger.verifyEquals(ts.get(0).getCls(), mtmp.get("DeliveryMethod"), "验证temps[0].DeliveryMethod");
				Logger.verifyEquals(ts.get(0).getTlid(), mtmp.get("TemplateId"), "验证temps[0].TemplateId");
			}
			// Logger.verifyEquals(m.get("templates"),
			// m1.get("temps"),"验证temps");
			Logger.verifyEquals(productsmapdate.get("wtu"), m1.get("unit"), "验证unit");
		} else if (i == 2) {
			Map m1 = ssw.getProductCatalogInfo(pid, ckey).get(0);
			Logger.comment("验证ProductCatalogInfo");
			// clist中包含所有商品规格
			List<Map<String, Object>> clist = (List<Map<String, Object>>) m1.get("clist");
			for (Map<String, Object> map : clist) {
				// 验证修改的那个cid对应的数据
				if (map.get("cid").toString().equals(productsmapdate.get("cid").toString())) {
					Logger.verifyEquals(map.get("isexd"), productsmapdate.get("isexd"), "验证isexd");
					Logger.verifyEquals(map.get("presale"), productsmapdate.get("presale"), "验证presale");
					Logger.verifyEquals(Double.valueOf(map.get("price").toString()), Double.valueOf(productsmapdate.get("price").toString()), "验证price");
					Logger.verifyEquals(Double.valueOf(map.get("vip").toString()), Double.valueOf(productsmapdate.get("vip").toString()), "验证vip");
					Logger.verifyEquals(Double.valueOf(map.get("new").toString()), Double.valueOf(productsmapdate.get("new").toString()), "验证new");
					Logger.verifyEquals(Double.valueOf(map.get("weight").toString()), Double.valueOf(productsmapdate.get("weight").toString()), "验证weight");
					Logger.verifyEquals(map.get("pkg"), productsmapdate.get("pkg"), "验证pkg");
					// 验证props
					List<Props> attrs = (List<Props>) productsmapdate.get("attrs");
					if (attrs != null && !attrs.isEmpty()) {
						for (Props props : attrs) {
							Map mprops = ((List<Map>) map.get("props")).get(0);
							Logger.verifyEquals(mprops.get("name"), props.getName(), "验证name");
							Logger.verifyEquals(mprops.get("value"), props.getValue(), "验证value");
							Logger.verifyEquals(mprops.get("pic"), props.getPic(), "pic");
						}
					}
				}
			}
		} else if (i == 3) {
			Map m1 = ssw.getProductPictureInfo(pid, pickey).get(0);
			Logger.comment("验证ProductPictureInfo");
			Logger.verifyEquals(productsmapdate.get("mainpics"), m1.get("mainpics"), "验证mainpics");
			Logger.verifyEquals(productsmapdate.get("descpics"), m1.get("descpics"), "验证descpics");
			Logger.verifyEquals(productsmapdate.get("sizepics"), m1.get("sizepics"), "验证sizepics");
			Logger.verifyEquals(productsmapdate.get("notice"), m1.get("notice"), "验证notice");
			Logger.verifyEquals(productsmapdate.get("notipics"), m1.get("notipics"), "验证notipics");
			Logger.verifyEquals(productsmapdate.get("intro"), m1.get("intro"), "验证intro");
			Logger.verifyEquals(productsmapdate.get("intropics"), m1.get("intropics"), "验证intropics");
			Logger.verifyEquals(productsmapdate.get("cdpics"), m1.get("cdpics"), "验证cdpics");

			List<Props> attrs = (List<Props>) productsmapdate.get("props");
			if (attrs != null && !attrs.isEmpty()) {
				for (Props props : attrs) {
					Map mprops = ((List<Map>) m1.get("props")).get(0);
					Logger.verifyEquals(props.getKey(), mprops.get("key"), "验证key");
					Logger.verifyEquals(props.getValue(), mprops.get("value"), "验证value");
				}
			}
			
			Map v= (Map) productsmapdate.get("v");
			if (v != null ) {
				Logger.verifyEquals(v.get("u"), ((Map)m1.get("v")).get("u"), "验证v.u");
				Logger.verifyEquals(v.get("l"), ((Map)m1.get("v")).get("l"), "验证v.l");
				Logger.verifyEquals(v.get("w"), ((Map)m1.get("v")).get("w"), "验证v.w");
				Logger.verifyEquals(v.get("h"), ((Map)m1.get("v")).get("h"), "验证v.h");
				Logger.verifyEquals(v.get("s"), ((Map)m1.get("v")).get("s"), "验证v.s");
			}
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductSnapshot_001() {
		Logger.start(true, "新增商品快照成功");
		try {
			String productId = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation(3383).getProductId();
			addproductsnapshotBean.setActionType("ActionTest");
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotBean.setProductId(productId);
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyEquals("ok", addproductsnapshotCall.getReturnData(), "验证返回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AddProductSnapshot_002() {
		Logger.start(true, "不输入商品id失败");
		try {
			// SnapShotWapper ssw=new SnapShotWapper();
			// ArrayList<Map> list = ssw.getProductVersionInfoLens(1, null);
			// for (Map map : list) {
			// addproductsnapshotBean.setProductId(map.get("pid").toString());
			// }
			addproductsnapshotBean.setActionType("ActionTest");
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyEquals("fail", addproductsnapshotCall.getReturnData(), "验证返回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductSnapshot_003() {
		Logger.start(true, "只修改商品信息pkey成功");
		try {

			ArrayList<Map> list = ssw.getProductVersionInfoLens(2, null);
			String pid = list.get(1).get("pid").toString();
			Map m = UpdateInfo(pid, 1);
			Logger.debug(m);
			Thread.sleep(5000);
			addproductsnapshotBean.setActionType("ActionTest");
			addproductsnapshotBean.setProductId(pid);
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyEquals("ok", addproductsnapshotCall.getReturnData(), "验证返回");
			verifyDB(m, pid, 1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductSnapshot_004() {
		Logger.start(true, "只修改规格信息ckey成功");
		try {
			SnapShotWapper ssw = new SnapShotWapper();
			ArrayList<Map> list = ssw.getProductVersionInfoLens(1, null);
			String pid = list.get(0).get("pid").toString();
			Map m = UpdateInfo(pid, 2);
			Logger.debug(m);
			Thread.sleep(2000);
			addproductsnapshotBean.setActionType("ActionTest");
			addproductsnapshotBean.setProductId(pid);
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyEquals("ok", addproductsnapshotCall.getReturnData(), "验证返回");
			verifyDB(m, pid, 2);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductSnapshot_005() {
		Logger.start(true, "只修改图片信息pickey成功");
		try {
			SnapShotWapper ssw = new SnapShotWapper();
			ArrayList<Map> list = ssw.getProductVersionInfoLens(1, null);
			String pid = list.get(0).get("pid").toString();
			Map m = UpdateInfo(pid, 3);
			Logger.debug(m);
			addproductsnapshotBean.setActionType("ActionTest");
			addproductsnapshotBean.setProductId(pid);
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyEquals("ok", addproductsnapshotCall.getReturnData(), "验证返回");
			verifyDB(m, pid, 3);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductSnapshot_006() {
		Logger.start(true, "新增商品快照时发现版本旧于products里面的ver不更新");
		try {
			String pid = ProductPriceCallService.getProdPriceWithActivity_NoNewBuyerAndNoIsolation(3383).getProductId();
			//pid数据只能用1次
			addproductsnapshotCall = new AddProductSnapshotCall("snapshot");
			Map m = UpdateInfo(pid, 1);
//			m.put("action", 0);
			// 更新products ver
			int ver = Integer.valueOf(ps.getProductsBySpid(pid).get(0).get("ver").toString().replaceAll("\\.", "")) + 1000;
			ps.updateProductsBySpid(pid, "ver", ver);
			Thread.sleep(2000);
			addproductsnapshotBean.setActionType("SaveActivity");
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotBean.setProductId(pid);
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyIsContains("ok", addproductsnapshotCall.getReturnData(), "验证返回");
			verifyDB(m, pid, 1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductSnapshot_007() {
		Logger.start(true, "修改全部商品信息成功");
		try {

			ArrayList<Map> list = ssw.getProductVersionInfoLens(2, null);
			String pid = list.get(1).get("pid").toString();
			Map m1 = UpdateInfo(pid, 1);
			Map m2 = UpdateInfo(pid, 2);
			Map m3 = UpdateInfo(pid, 3);
			Thread.sleep(5000);
			addproductsnapshotBean.setActionType("ActionTest");
			addproductsnapshotBean.setProductId(pid);
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyEquals("ok", addproductsnapshotCall.getReturnData(), "验证返回");
			verifyDB(m1, pid, 1);
			verifyDB(m2, pid, 2);
			verifyDB(m3, pid, 3);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductSnapshot_008() {
		Logger.start(true, "修改规格、Catalogs.props、ProductDescExtra.props、Product.templates,序列化对象在Ymt_ProductChangeLog中记录正确JIRACONN-14988");
		try {

			ArrayList<Map> list = ssw.getProductVersionInfoLens(100, null);
			String pid = list.get(new Random().nextInt(99)).get("pid").toString();
			List<Templates> templates = new ArrayList<>();
			for (int i = 0; i < 3; i++) {
				Templates e = new Templates();
				e.setCls(i);
				e.setTlid(i + 1);
				templates.add(e);
			}
			ps.updateProductsBySpid(pid, "templates", templates);

			Map<String, Object> m2 = ps.getCatalogsBySpid(pid).get(0);
			ps.updateCatalogsByCid(m2.get("cid").toString(), "props", null);
			
			ps.updateCatalogsByCid(m2.get("cid").toString(), "cid", TestDataManager.getRandomUUID().toString());

			List<Props> props = new ArrayList<>();
			for (int i = 0; i < 3; i++) {
				Props e = new Props();
				e.setKey("key" + i);
				e.setValue("value" + i);
				props.add(e);
			}
			ps.updateProductDescExtraBySpid(pid, "props", props);

			Thread.sleep(5000);
			addproductsnapshotBean.setActionType("ActionTest");
			addproductsnapshotBean.setProductId(pid);
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyEquals("ok", addproductsnapshotCall.getReturnData(), "验证返回");
			//TODO 验证[integratedproduct].[dbo].[Ymt_ProductChangeLog] 序列化正确 没有看不懂的数据
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductSnapshot_009() {
		Logger.start(true, "修改图片信息pickey内容为空白字符不会修改成功JIRACONN-15588");
		try {
			SnapShotWapper ssw = new SnapShotWapper();
			ArrayList<Map> list = ssw.getProductVersionInfoLens(1, null);
			String pid = list.get(0).get("pid").toString();
			Map m = UpdateInfo(pid, 3);
			ps.updateProductDescExtraBySpid(pid, "intropics", Arrays.asList(""));
			m.put("intropics", Arrays.asList(""));
			Logger.debug(m);
			addproductsnapshotBean.setActionType("ActionTest");
			addproductsnapshotBean.setProductId(pid);
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyEquals("ok", addproductsnapshotCall.getReturnData(), "验证返回");
			verifyDB(m, pid, 3);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
    @Category({P1.class})
    @TestCase
    public void Tc_AddProductSnapshot_010() throws Exception {
        Logger.start(true,"发布商品，拼邮发货，海外发货,发布成功-pdt字段同步到快照");
        try{
            AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(3383);
            AddSellerProductCall addSellerProductCall=new AddSellerProductCall();
           
            addProdReq.getProduct().setPackageDeliveryType(1);
            addSellerProductCall.setData(addProdReq);
            addSellerProductCall.callService();
            Logger.verifyEquals("200",addSellerProductCall.getString("Code"),"验证code");
            String pid = addSellerProductCall.getJsonObject().get("Data").getAsJsonObject().get("ProductId").getAsString();
//            Map m = UpdateInfo(pid, 1);
            addproductsnapshotBean.setActionType("ActionTest");
			addproductsnapshotBean.setProductId(pid);
			addproductsnapshotBean.setAppId("AutoTest");
			addproductsnapshotCall.setData(addproductsnapshotBean);
			addproductsnapshotCall.callService();
			Logger.verifyEquals("ok", addproductsnapshotCall.getReturnData(), "验证返回");
			Thread.sleep(2000);
			List<String> keys = new ArrayList<>();
			keys.add("pid");
			keys.add("ver");
			keys.add("ckey");
			keys.add("pkey");
			keys.add("pickey");
			keys.add("pickey");
			ArrayList<Map> list = ssw.getProductVersionInfoLens(pid, 1, keys);
			String pkey = list.get(0).get("pkey").toString();
			String ckey = list.get(0).get("ckey").toString();
			String pickey = list.get(0).get("pickey").toString();
			Map m1 = ssw.getProductCoreInfo(pid, pkey).get(0);
			Logger.comment("验证ProductCoreInfo");
			Logger.verifyEquals(addProdReq.getProduct().getPackageDeliveryType(), m1.get("pdt"), "验证pdt");
        }catch(Exception e){
            Logger.fail(e);
        }
    }

}